package org.iotp.infomgt.data.common;

import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

public class UUIDConverter {

  public static UUID fromString(String src) {
    return UUID.fromString(src.substring(7, 15) + "-" + src.substring(3, 7) + "-1" + src.substring(0, 3) + "-"
        + src.substring(15, 19) + "-" + src.substring(19));
  }

  public static String fromTimeUUID(UUID src) {
    if (src.version() != 1) {
      throw new IllegalArgumentException("Not a time UUID!");
    }
    String str = src.toString();
    return str.substring(15, 18) + str.substring(9, 13) + str.substring(0, 8) + str.substring(19, 23)
        + str.substring(24);
  }

  public static List<String> fromTimeUUIDs(List<UUID> uuids) {
    if (uuids == null) {
      return null;
    }
    return uuids.stream().map(UUIDConverter::fromTimeUUID).collect(Collectors.toList());
  }

}
